package com.schuxl.htmlobserver.dataobject;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.lang.StringEscapeUtils;

import util.Util;

public abstract class Ad implements Serializable {
	
	private static final long serialVersionUID = -2899310839780666011L;
	
	protected String bikeName=""; //Title des Bikes aus dem model-filter
	protected Calendar issueDate=null;//Datum an dem die Anzeige zum ersten mal eingelesen wurde (fuer Ablaufdatum)
	protected String priceCalculation=""; //Beschreibung der Preiserhebung fuer Filter



	protected String title="";
	protected String link="";
	protected String imageLink="";
	protected Integer year = null; 
	protected String kilometers="";
	protected Integer ccm = null;
	protected Integer price = null;
	protected String dealer="Unbekannt"; //Wird spaeter ueberschrieben (falls bekannt)
	protected String location="";
	protected String durationDobersberg = "";
	protected String distanceDobersberg = "";
	protected String linkDobersberg = "";
	protected String durationWien = "";
	protected String distanceWien = "";
	protected String linkWien = "";
	
	



	/**
	 * Liefert die HTML Darstellung dieser Ad
	 * @return HTML-Representation
	 */
	public String getHtmlRepresentation() {
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append("<h3>").append(title).append(" (").append(bikeName).append(")").append("</h3><br/>");
		if(imageLink!=null && imageLink.length()>0)
			stringBuffer.append("<a href=\"").append(link).append("\">").append("<img width=\"120\" src=\"").append(imageLink).append("\" /></a>").append("<br/><br/>");
		stringBuffer.append("<table>");
		stringBuffer.append("<tr><td>").append("<b>Preis:</b> </td><td>").append(Util.formatPrice(price)).append(",-").append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Erstzul.:</b> </td><td>").append(year).append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Standort:</b> </td><td>").append(StringEscapeUtils.escapeHtml(location)).append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Laufl.:</b> </td><td>").append(kilometers).append(" km").append("</td></tr>");
		if(ccm!=null)
			stringBuffer.append("<tr><td>").append("<b>Hubraum:</b> </td><td>").append(ccm).append(" ccm").append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Anbieter:</b> </td><td>").append(StringEscapeUtils.escapeHtml(dealer)).append("</td></tr>");
		stringBuffer.append("<tr><td colspan=\"2\" height=\"10\"></td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Preisberechnung:</b> </td><td>").append(StringEscapeUtils.escapeHtml(priceCalculation)).append("</td></tr>");
		if(durationWien.equals("")==false)
			stringBuffer.append("<tr><td>").append("<b>Von Wien:</b> </td><td>").append(distanceWien+", "+durationWien+", ").append("<a href=\""+linkWien+"\">Route</a>").append("</td></tr>");
		if(durationDobersberg.equals("")==false)
			stringBuffer.append("<tr><td>").append("<b>Von Dobersberg:</b> </td><td>").append(distanceDobersberg+", "+durationDobersberg+", ").append("<a href=\""+linkDobersberg+"\">Route</a>").append("</td></tr>");
		stringBuffer.append("<tr><td>").append("<b>Link:</b> </td><td>").append("<a href=\"").append(link).append("\">").append(link).append("</a>").append("</td></tr>");
		stringBuffer.append("</table>");
		
		return stringBuffer.toString();
	}
	
	

	
	public String getBikeName() {
		return bikeName;
	}
	public void setBikeName(String bikeName) {
		this.bikeName = bikeName;
	}
	public Calendar getIssueDate() {
		return issueDate;
	}
	public void setIssueDate(Calendar issueDate) {
		this.issueDate = issueDate;
	}
	public String getPriceCalulation() {
		return priceCalculation;
	}
	public void setPriceCalculation(String priceCalculation) {
		this.priceCalculation = priceCalculation;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
	public String getImageLink() {
		return imageLink;
	}
	public void setImageLink(String imageLink) {
		this.imageLink = imageLink;
	}
	public String getKilometers() {
		return kilometers;
	}
	public void setKilometers(String kilometers) {
		this.kilometers = kilometers;
	}
	public Integer getCcm() {
		return ccm;
	}
	public void setCcm(Integer ccm) {
		this.ccm = ccm;
	}
	public Integer getYear() {
		return year;
	}
	public void setYear(Integer year) {
		this.year = year;
	}
	public Integer getPrice() {
		return price;
	}
	public void setPrice(Integer price) {
		this.price = price;
	}
	public String getDealer() {
		return dealer;
	}
	public void setDealer(String dealer) {
		this.dealer = dealer;
	}
	public String getLocation() {
		return location;
	}
	public void setLocation(String location) {
		this.location = location;
	}
	public String getDurationDobersberg() {
		return durationDobersberg;
	}
	public void setDurationDobersberg(String durationDobersberg) {
		this.durationDobersberg = durationDobersberg;
	}
	public String getDistanceDobersberg() {
		return distanceDobersberg;
	}
	public void setDistanceDobersberg(String distanceDobersberg) {
		this.distanceDobersberg = distanceDobersberg;
	}
	public String getLinkDobersberg() {
		return linkDobersberg;
	}
	public void setLinkDobersberg(String linkDobersberg) {
		this.linkDobersberg = linkDobersberg;
	}
	public String getDurationWien() {
		return durationWien;
	}
	public void setDurationWien(String durationWien) {
		this.durationWien = durationWien;
	}
	public String getDistanceWien() {
		return distanceWien;
	}
	public void setDistanceWien(String distanceWien) {
		this.distanceWien = distanceWien;
	}
	public String getLinkWien() {
		return linkWien;
	}
	public void setLinkWien(String linkWien) {
		this.linkWien = linkWien;
	}




	@Override
	public String toString() {
		return "Ad [bikeName=" + bikeName + ", issueDate=" + issueDate
				+ ", priceCalculation=" + priceCalculation + ", title=" + title
				+ ", link=" + link + ", imageLink=" + imageLink + ", year="
				+ year + ", kilometers=" + kilometers + ", ccm=" + ccm
				+ ", price=" + price + ", dealer=" + dealer + ", location="
				+ location + ", durationDobersberg=" + durationDobersberg
				+ ", distanceDobersberg=" + distanceDobersberg
				+ ", linkDobersberg=" + linkDobersberg + ", durationWien="
				+ durationWien + ", distanceWien=" + distanceWien
				+ ", linkWien=" + linkWien + "]";
	}




	// ACHTUNG    ACHTUNG    ACHTUNG (Der ImageLink darf beim Compare und HashCode nicht verglichen werden)
	// ACHTUNG    ACHTUNG    ACHTUNG (Die Location darf beim Compare und HashCode nicht verglichen werden - da diese nach dem Filtern noch geaendert wird)
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((dealer == null) ? 0 : dealer.hashCode());
		result = prime * result + ((kilometers == null) ? 0 : kilometers.hashCode());
		result = prime * result + ((link == null) ? 0 : link.hashCode());
		result = prime * result + ((price == null) ? 0 : price.hashCode());
		result = prime * result + ((title == null) ? 0 : title.hashCode());
		result = prime * result + ((year == null) ? 0 : year.hashCode());
		return result;
	}
	
												
	

	// ACHTUNG    ACHTUNG    ACHTUNG (Der ImageLink darf beim Compare und HashCode nicht verglichen werden)
	// ACHTUNG    ACHTUNG    ACHTUNG (Die Location darf beim Compare und HashCode nicht verglichen werden - da diese nach dem Filtern noch geaendert wird)
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Ad other = (Ad) obj;
		if (dealer == null) {
			if (other.dealer != null)
				return false;
		} else if (!dealer.equals(other.dealer))
			return false;
		if (kilometers == null) {
			if (other.kilometers != null)
				return false;
		} else if (!kilometers.equals(other.kilometers))
			return false;
		if (link == null) {
			if (other.link != null)
				return false;
		} else if (!link.equals(other.link))
			return false;
		if (price == null) {
			if (other.price != null)
				return false;
		} else if (!price.equals(other.price))
			return false;
		if (title == null) {
			if (other.title != null)
				return false;
		} else if (!title.equals(other.title))
			return false;
		if (year == null) {
			if (other.year != null)
				return false;
		} else if (!year.equals(other.year))
			return false;
		return true;
	}
	
	
	
	
	
	
	

}
